<?php
namespace app\admin\model;

use think\Model;
class product extends Model
{

    public function getproductList($term_id){
        $product_list = $this->where('term_id='.$term_id)->select();
        return $product_list;
    }

    public function addproduct($termId, $tagsValue){
        //待删除product表中的model_id列
        $data['model_id'] = D('Term')->getTermInfo($termId)['model_id'];

        if(!empty($tagsValue))
            $data['tags_value'] = $tagsValue;

        //$data['seo_title'] = I('post.seo_title');
        //$data['seo_keywords'] = I('post.seo_keywords');
        //$data['seo_description'] = I('post.seo_description');
        $data['cover_img'] = I('post.cover_img');
        $data['name'] = I('post.title');
        //新增字段
        $data['area'] = I('post.area');
        $data['prise'] = I('post.prise');
        $data['huxing'] = I('post.huxing');                
        //新增字段 
        $data['intercept'] = I('?post.intercept')? I('post.interncept'): 0;
        $data['term_id'] = $termId;
        $data['keywords'] = I('post.keywords');
        $data['description'] = I('post.description');
        $data['content'] = I('post.content');
        $data['status'] = I('post.status');
        $data['rec_ok'] = I('post.rec_ok');
        $data['top_ok'] = I('post.top_ok');
        $data['built'] = I('post.built');
        $data['fangtype'] = I('post.fangtype');
        $data['create_time'] = strtotime(I('post.create_time'));
        $add_product = $this->add($data);
        return $add_product;
    }

    /**
     * 删除内容
     * @param mixed $id 待删除内容的ID，可以是数字或数组
     */
    public function delproduct($id){
        $del_product =$this->where(['id'=>$id])->delete();
        return $del_product;
    }

    public function getInfo($id=null){
        if(empty($id))
            $id = I('get.id');
        $result = $this->find($id);
        $result['model_id'] = D('Term')->getTermInfo($result['term_id'])['model_id'];
        return $result;
    }


    public function postEdit($tagsValue){
        if(!empty($tagsValue))
            $data['tags_value'] = $tagsValue;
        $where['id'] = I('post.id');
        $data['model_id'] = I('post.model_id');
        if(0==I('post.term_id'));
        if(D('Term')->hasChild(I('post.term_id')))
            return false;
        $data['term_id'] = I('post.term_id');
        $data['intercept'] = I('?post.intercept')? I('post.interncept'): 0;
        $data['name'] = I('post.title');
        //新增字段
        $data['area'] = I('post.area');
        $data['prise'] = I('post.prise');
        $data['huxing'] = I('post.huxing');                
        //新增字段        
        $data['keywords'] = I('post.keywords');
        $data['description'] = I('post.description');
        $data['content'] = I('post.content');
        $data['cover_img'] = I('post.cover_img');
        $data['status'] = I('post.status');
        $data['rec_ok'] = I('post.rec_ok');
        $data['top_ok'] = I('post.top_ok');
        $data['built'] = I('post.built');
        $data['fangtype'] = I('post.fangtype');
        $data['seo_title'] = I('post.seo_title');
        $data['seo_keywords'] = I('post.seo_keywords');
        $data['seo_description'] = I('post.seo_description');
        $data['create_time'] = strtotime(I('post.create_time'));
        $post_edit = $this->where($where)->save($data);
        return $post_edit;
    }

    /**
     * 批量删除
     * 待废弃
     */
    public function delId($del_id){
        $map['id']  = array('in',$del_id);
        $delet_id = $this->where($map)->delete();
        return $delet_id;
    }

    public function listOrder($listorder,$listorder_id)
    {
        $data['listorder']=$listorder;
        $list_order = $this->where('id='.$listorder_id)->save($data);
        return $list_order;
    }

    //保留原有发布内容的形式，增加侧边栏发布内容功能
    public function addSliderproduct()
    {

        $data['name'] = I('post.title');
        //$data['seo_title'] = I('post.seo_title');
        //$data['seo_keywords'] = I('post.seo_keywords');
        //$data['seo_description'] = I('post.seo_description');
        $data['intercept'] = I('?post.intercept')? I('post.interncept'): 0;
        $data['term_id'] = I('post.term_id');
        if(!empty($data['term_id']));
        if(D('Term')->hasChild($data['term_id']))
            return false;
        $data['model_id'] = D('Term')->getTermInfo($data['term_id'])['model_id'];
        $data['keywords'] = I('post.keywords');
        $data['description'] = I('post.description');
        $data['product'] = I('post.product');
        $data['status'] = I('post.status');
        $data['rec_ok'] = I('post.rec_ok');
        $data['top_ok'] = I('post.top_ok');
        $data['cover_img'] = I('post.cover_img');
        $data['create_time'] = strtotime(I('post.create_time'));
        $addSliderproduct = $this->add($data);
        return $addSliderproduct;
    }
}

